package com.snail.mobile.sim.oss.util;

import java.util.Date;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;



public class StringUtil {
	public static  String getStringForarray(String[]str){
		if(ArrayUtils.isNotEmpty(str)){
			String result="";
			StringBuffer sb=new StringBuffer();
			String strtemp="";
			
			for(String s:str){
				 strtemp=sb.append(s).append(",").toString();
				 result=strtemp.substring(0,strtemp.lastIndexOf(","));
				
			}
			return result;
		}
		return "";
	}
	
	public static String getString(String str){
		if(!"-1".equals(str.lastIndexOf(","))){
			return str.substring(0,str.lastIndexOf(","));
		}
		return str;
	}
	public static String getStringBySymbol(String str,String symbol){
		if(!"-1".equals(str.lastIndexOf(symbol))){
			return str.substring(0,str.lastIndexOf(symbol));
		}
		return str;
	}
	/**
	 * 判断对象是否为空
	 * @param obj
	 * @return
	 */
	public static  boolean isNotNull(Object obj){
		if(obj == null || obj.toString().isEmpty())
			return false;
		return true;
	}
	
	 /**
     * 是否为空如果不等于空并且是数值型是转换为Date型
     *
     * @param o 值
     * @return 返回空或转换后的值
     */
    public static Date isDateNull(Object o) {
        if (o != null && !"".equals(o.toString())) {
            Object obj = DateUtils.parseDate(o.toString());
            if (obj == null) {
                obj = DateUtils.parseDate(o.toString(), DateUtils.DATE_YMD);
            }
            return (Date) obj;
        }
        return null;
    }
	
    
}
